<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table{
            border-collapse: collapse;
        }
        table td{
            padding: 20px 60px;
        }
        table tr:nth-child(odd){
            background-color: rgb(red, green, blue);
        }
        table tr:nth-child(even){
            background-color: pink;
        }
        .active{
            background-color: black;
        }
    </style>
</head>
<body>
    <table border="1">
        <tr>
            <td>序号</td>
            <td>班级</td>
            <td>姓名</td>
        </tr>
        <tr>
            <td>1</td>
            <td>学前一班</td>
            <td>王五</td>
        </tr>
        <tr>
            <td>2</td>
            <td>学前二班</td>
            <td>李四</td>
        </tr>
    </table>
    <script>
        document.querySelectorAll('td').forEach(item=>{
            item.addEventListener('click',function(){
                let od=document.querySelector('table .active')
                if(od){
                    od.classList.remove('active')
                }
                this.classList.add('active')
            })
        })
    </script>
</body>
</html>